package com.yanqu.road.server.cmd.activity.shuihu;

import com.yanqu.road.entity.activity.shuihu.config.ShuiHuConfig;
import com.yanqu.road.pb.activity.ShuiHuActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.shuihu.ShuiHuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SHUIHU_ACTIVITY_GET_NOTICE, desc = "获取公告")
public class GetShuiHuNoticeCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ShuiHuConfig shuiHuConfig = ShuiHuMgr.getShuiHuConfig();

        if (shuiHuConfig == null || !ActivityMgr.activityInShowTime(shuiHuConfig.getActivityInfo())) {
            ret = GameErrorCode.E_SHUIHU_ACTIVITY_NO_OPEN;
            return;
        }

        // 到跨服拿数据
        ShuiHuActivityProto.CrossGetShuiHuNoticeReqMsg.Builder reqMsg = ShuiHuActivityProto.CrossGetShuiHuNoticeReqMsg.newBuilder();
        reqMsg.setActivityId(shuiHuConfig.getActivityId());
        reqMsg.setUserId(player.getUserId());
        reqMsg.setServerId(player.getUserInfo().getOriginalServerId());
        player.sendPacket(CrossProtocol.C2_SHUIHU_ACTIVITY_GET_NOTICE, reqMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ShuiHuActivityProto.GetShuiHuNoticeRespMsg.Builder builder = ShuiHuActivityProto.GetShuiHuNoticeRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SHUIHU_ACTIVITY_GET_NOTICE, builder);
        }
    }
}
